package com.blockmeta.bbs.immodule.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.blockmeta.bbs.immodule.R;

import java.lang.reflect.Field;


public abstract class IMPopup {
    protected Context m_context;
    public CommonPopup m_dialog;
    private Window window = null;
    View tView;

    public IMPopup(Context pContext, int pLayoutID) {
        m_context = pContext;


        m_dialog = new CommonPopup(pContext, R.style.AlertDialog);
        window = m_dialog.getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP&&window!=null) {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        }

        FrameLayout tFrameLayout = new FrameLayout(pContext);

        tView = LayoutInflater.from(m_context).inflate(pLayoutID, tFrameLayout);
        initView(tView);
        m_dialog.setModal();

        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        m_dialog.setContentView(tFrameLayout, params, Gravity.CENTER_HORIZONTAL);
        m_dialog.setOnDismissListener(new Dialog.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                IMPopup.this.onDismiss(dialog);
            }
        });
    }

    protected abstract void onDismiss(DialogInterface dialog);

    protected abstract void initView(View pView);

    protected final void showDialog() {
        m_dialog.show();
    }


    protected final void dismissDialog() {
        m_dialog.dismiss();
    }
}
